package com.zhang.demo.json;

import com.google.gson.*;

import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;

public class JsonParseText {


    public static void main(String[] args) throws FileNotFoundException, URISyntaxException {
        URL url = JsonParseText.class.getClassLoader().getResource("text.txt");
        File file = new File(url.toURI());
        JsonParser parse =new JsonParser();  //创建json解析器
        JsonObject json=(JsonObject) parse.parse(new FileReader(file));

        JsonObject data = json.getAsJsonObject("data");
       // System.out.println(data);

        JsonArray modules = data.getAsJsonArray("modules");

        //System.out.println(modules.get(1).getAsJsonObject().getAsJsonArray("folders").get(0).getAsJsonObject().getAsJsonArray("children"));

        JsonArray children = modules.get(1).getAsJsonObject().getAsJsonArray("folders").get(0).getAsJsonObject().getAsJsonArray("children");

        for (int i = 0; i < children.size() ; i++) {
            JsonObject  o = children.get(i).getAsJsonObject();

            //System.out.println(o);
            JsonElement reqs = o.get("responseArgs");
            JsonElement resps = o.get("responseArgs");
            //System.out.println(reqs);
            String req = reqs.getAsJsonPrimitive().getAsString().replace("\\","");
            String resp = resps.getAsJsonPrimitive().getAsString().replace("\\","");

            //String req = reqs.getAsJsonPrimitive().getAsString();
            //String resp = resps.getAsJsonPrimitive().getAsString();

            //req = req.substring(1,req.length()-1);
            //resp = resp.substring(1,resp.length()-1);
            System.out.println(req);
            //System.out.println(resp);
            JsonArray json1= new JsonParser().parse(req).getAsJsonArray();
            //System.out.println(reqss);
            //System.out.println(respss);
            for (int j = 0; j < json1.size() ; j++) {
                JsonObject jo = json1.get(i).getAsJsonObject();
                System.out.println(jo);
                String name = jo.get("name").getAsString();
                System.out.println(name);
            }



            //System.out.println(json1);
        }


        JsonArray jsonArray = json.getAsJsonArray("responseArgs");
        //System.out.println(jsonArray);



    }
}
